package in.ac.dei.edrp.cms.daoimpl.updateprestaging;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import in.ac.dei.edrp.cms.dao.updateprestaging.UpdatePrestagingConnect;
import in.ac.dei.edrp.cms.domain.cgpadivision.CgpaDivisionInfoGetter;
import in.ac.dei.edrp.cms.domain.updateprestaging.UpdatePrestagingInfoGetter;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

public class UpdatePrestagingImpl extends SqlMapClientDaoSupport implements UpdatePrestagingConnect {

	@SuppressWarnings("unchecked")
	public List<UpdatePrestagingInfoGetter> getRecords(
			UpdatePrestagingInfoGetter input) {
		System.out.println("Rohit impl");
		UpdatePrestagingInfoGetter val =new UpdatePrestagingInfoGetter();
		
		List<UpdatePrestagingInfoGetter> values = new ArrayList<UpdatePrestagingInfoGetter>();
		
		values = getSqlMapClientTemplate().queryForList("updateprestaging.getErrorRecords",val);
		System.out.println(values.size()+"result size");
		
		return values;
	}
	
	/**
	    * Method for deleting records(divisions)for the concerned university
	    * @param input Object of the referenced bean class
	    * @param items selected items to be deleted
	    * @return String
	    */
	    public String deletePrestagingRecords(List<UpdatePrestagingInfoGetter> input) {
	    	System.out.println("delete impl");
	    	
	    			int del=0;
	    			for(int i=0;i<input.size();i++){
	    				
	    				getSqlMapClientTemplate()
		                .delete("updateprestaging.deletePrestageRecords",input.get(i));
	    				del=del+1;
	    			}
	                
	    			if(del!=0){
	         return "success";
	    			}
	    			else{
	    		return "failure";		
	    			}
	    }

	public String updatePrestagingDetails(UpdatePrestagingInfoGetter detail) {
			System.out.println("update impl");
			
			try{
          getSqlMapClientTemplate()
	                .update("updateprestaging.updatePrestageRecords",detail);
          System.out.println("suc");
			}
			catch (Exception e) {
				System.out.println("fal");
				return "failure";
			}

	        return "success";
	
	}

	

}
